﻿namespace WFBot.Data.Configuration
{
    using WFBot.Framework.Domain;
    using Microsoft.Data.Objects;

    public class ResponseConfiguration : EntityConfiguration<Response>
    {
        public ResponseConfiguration()
        {
            HasKey(r => r.Id);

            Property(r => r.Id).IsIdentity();
            Property(r => r.Answer).IsRequired().HasMaxLength(2000);
            Property(r => r.Date);

            Relationship(r => r.Visitor).FromProperty(v => v.Responses).IsRequired();
            Relationship(r => r.Question).IsRequired();

            MapSingleType(r => new
            {
                r.Id,
                VisitorId = r.Visitor.Id,
                QuestionId = r.Question.Id,
                r.Answer,
                r.Date
            }).ToTable("Responses");
        }
    }
}
